package com.csdj.t309tgspringboot.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.applet.Applet;
import java.applet.AudioClip;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Calendar;

@Component
public class TestJob {

    private Logger logger = LoggerFactory.getLogger("job");

    /*@Scheduled(fixedRate = 5000)*/
    /*@Scheduled(cron = "0 0 8-12 * * ?")//每天八至十二点每小时执行一次*/
    /*@Scheduled(cron = "0 0 8,12 * * ?")//每天八和十二点执行一次*/
    /*@Scheduled(cron = "0 0 * * * ?")//每一小时执行一次*/
    /*@Scheduled(cron = "0 0 0/2 * * ?")//每两小时执行一次*/
    /*@Scheduled(cron = "0-3 * * * * ?")//每零到三秒每秒执行一次*/
    @Scheduled(cron = "0 0 8-11 ? * 2-6")
    @Scheduled(cron = "0 50 8-11 ? * 2-6")
    @Scheduled(cron = "0 30 1-4 ? * 2-6")
    @Scheduled(cron = "0 20 2-5 ? * 2-6")
    public void test(){
        /*try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        /*String filename="bgm/baozha.mp3";//文件路径
        try {
            BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(filename));
            Player player = new Player(buffer);//加载
            player.play();//开始播放
        } catch (Exception e) {
            System.out.println(e);
        }*/
    }

    /**
     * cron = "0 0,20,30,50 8-11,13-17 ? * 2-6"
     */
    private void play(){
        Calendar calendar = Calendar.getInstance();
        int i = calendar.get(Calendar.MINUTE);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        switch (i){
            case 0:
                if(hour == 13)break;
                break;
            case 20:
                if(hour == 13)break;
                break;
            case 30:
                break;
            case 50:
                break;
        }
    }
}
